import * as appService from "../services/app";
export default {
  namespace:'app',
  state:{
    user:[],
    menu:[],
    toggle:false,
    navBread:[],
  },
  subscriptions:{
    setupHistory({dispathc,history}){

    },
    setup({ dispatch }) {
      dispatch({ type: 'query',payload:{loading:true}});
    },
  },
  effects:{
    * query({payload},{call,put}){
      const {data} = yield call(appService.user);
      yield put({type:'update',payload: {user:data.user,menu:data.menu}});
    },
    * menuToggle({payload},{call,put,select}){
      yield put({type:'update',payload:{toggle:payload.toggle}})
    },
    * navBread({payload},{put,call}){
      yield put({type:'update',payload:{navBread:payload}});
    }}
  ,
  reducers:{
    update(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  }
}
